//
// global-message.js
// hs-admin
//
// Created by 区区电脑 on 2023/05/01.
//



const message = {
    state: {
        list: [],
    },
    mutations: {
        setGlobalMessageList(state, value) {
            state.list = value || [];
        },
        pushGlobalMessage(state, value) {
            state.list.push(value);
            state.list.sort((a, b) => {
                return b.id - a.id
            })
        },
        readMessage(state, value) {
            const index = state.list.findIndex(item => item.id === value);
            if (index > -1) {
                // 已读状态
                state.list[index].isRead = 1;
            }
        },
        readAllMessage(state, value) {
            state.list.map(item => {
                item.isRead = 1;
            })
        },
    },
    actions: {
        setGlobalMessageList({ commit }, value) {
            commit("setGlobalMessageList", value);
        },
        pushGlobalMessage({ commit }, value) {
            commit("pushGlobalMessage", value);
        },
        readMessage({ commit }, value) {
            commit("readMessage", value);
        },
        readAllMessage({ commit }, value) {
            commit("readMessage", value);
        },
    },
};

export default message;
